package com.swak.job.domain;

import java.io.Serializable;

import com.swak.job.JobConstants;
import com.swak.registry.URL;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 定时任务 - 调度器
 * 
 * @author 618lf
 */
@Data
@Accessors(chain = true)
public class JobDispatcherDTO implements Serializable {
	private static final long serialVersionUID = 1L;
	private String server;
	private String appName;
	private String group;
	private String worker;
	private Integer weight;
	private String leader;
	private String url;

	public static JobDispatcherDTO of(URL url) {
		JobDispatcherDTO dto = new JobDispatcherDTO();
		dto.setServer(url.getAddress());
		dto.setAppName(url.getApplication());
		dto.setGroup(url.getParameter(JobConstants.Group_key));
		dto.setWorker(url.getParameter(JobConstants.Worker_key));
		dto.setWeight(url.getParameter(JobConstants.Weight_key, 1));
		dto.setLeader(url.getParameter(JobConstants.Leader_key));
		return dto;
	}
}
